<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>


<body>
<script>
    function Persion(name, age, gender) {
        this.name = name;
        this.age = age;
    }


    Persion.prototype.toString = function () {
        return "Persion[name=" + this.name + ",age=" + this.age + "]"
    };

    var per = new Persion("张三", 18)
    var per1 = new Persion("李四", 20)
    var per2 = new Persion("王五", 8)
    var per3 = new Persion("赵六", 40)

    /**
     * 将这些对象放入数组中
     */
    var perArr=[per,per1,per2,per3]

    //创建一个函数将per中年龄满18的per对象放入数组中
    function getAdult(arr){
        var newArr=[];

        //遍历arr,获取arr中的Persion对象
        for (let i = 0; i <arr.length ; i++) {
            var  per = arr[i];
            if(per.age>=18){
                newArr.push(per)
            }
        }

        return newArr;
    }

    var result = getAdult(perArr);
    console.log(result)

</script>
</body>
</html>
